/**
 *
 * 覆盖PfBillEventHandler中的方法
 *
 * 向后台提交审批信息
 * @param approveContent 审批内容
 * @param auditAdvice 审批结果,通过/不通过/驳回
 */
function jkbxApprove(approveContent, approveAdvice,assigninfo, flexParam)
{
	if(getComponent('approveDialogId') != null)
		hideDialog("approveDialogId");
	showProgressDialog(trans('ml_wait'));
		
	var params = "&step=1&approveContent=" + approveContent + "&approveAdvice=" + approveAdvice;
	if(assigninfo != null)
		params += "&ASSIGN_INFO=" + assigninfo;
		
	if(flexParam != null)
		params += "&IS_FLEX=Y";
		
	var headDs = this.getMasterDs();
	var rows = headDs.getSelectedRows();
	var indices = headDs.getSelectedIndices(); 
	
	var count = indices.length;
    var arr = new Array();//主ds的pk数组
	var pkindex = getDatasetMasterKeyField(headDs);
	var djdl = null;;
	var djdlIndex = headDs.nameToIndex('djdl');
    for(var i = count - 1 ; i >= 0; i--){
    	var sRow = headDs.getRow(indices[i]);
    	arr.push(sRow.getCellValue(pkindex));
    	djdl = sRow.getCellValue(djdlIndex);
    }
	var cmd = new CommonCommand("approveByPks");
    cmd.setParameter("delpks=" + arr.join('$') + "&djdl=" + djdl + params);
    cmd.setReturnArgs([headDs,this,indices]);
    cmd.setReturnFunc(JkbxApproveReturnFun);
    cmd.setCallObj(this);
    cmd.exec();
};

/**
 * 单据审批的回调函数
 */
function JkbxApproveReturnFun(xml,returnArgs, isSuccess)
{
	hideProgressDialog();
	if(isSuccess){
		var headDs = returnArgs[0], oThis = returnArgs[1], allDelIndice = returnArgs[2];
		setCheckMan(headDs);//用来更新‘修改’按钮状态
		updateApproveStatus(headDs,xml,allDelIndice);
		if(oThis.afterAction(IPfAction.APPROVE) == false)
			return;		
	}
};

function updateApproveStatus(headDs,xmldoc,allDelIndice){
	var maps = parseXmlToMaps(xmldoc);
	var pkIndex = getDatasetMasterKeyField(headDs);
	for(var i=0; i<allDelIndice.length; i++){
		var rowIndex = allDelIndice[i];
		var row = headDs.getRow(rowIndex);
		var pk = row.getCellValue(pkIndex);
		if(maps[0].containsKey(pk)){//成功
			var v = maps[0].get(pk).split('$');
			headDs.setValueAt(rowIndex,headDs.nameToIndex('djzt'),v[1]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('spzt'),v[2]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('qcbz'),v[3]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('sxbz'),v[4]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('shr'), v[5],true);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('shrq'),v[6]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('ts'),v[7]);
			headDs.setValueAt(rowIndex,headDs.nameToIndex('jsrq'),v[8]);

			billUI.eventHandler.callAllDsClearStatus();
			var billStatus = billUI.eventHandler.getBillStatus(headDs, row);
			billUI.setTotalUIStatus(IBillOperate.OP_NOTEDIT, billStatus);
		}
	}	
}




